package vip.zhenzicheng.jpa.base;

import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 公共审计类
 *
 * @author zhenzicheng
 * @date 2023-03-28 16:27
 */
@MappedSuperclass
@Getter
@Setter
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseAuditEntity implements Serializable {
    private static final long serialVersionUID = 2795505916226485983L;

    @Column(name = "is_delete", columnDefinition = "TINYINT(1) DEFAULT 0")
    protected Boolean isDelete;

    @Column(name = "created_by", length = 50, updatable = false)
    @CreatedBy
    protected String createdBy;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created_time", updatable = false, columnDefinition = "DATETIME NULL DEFAULT CURRENT_TIMESTAMP")
    @CreatedDate
    protected Date createdTime;

    @Column(name = "updated_by", length = 50)
    @LastModifiedBy
    protected String updatedBy;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "updated_time", columnDefinition = "DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
    @LastModifiedDate
    protected Date updatedTime;

}
